package test.sign;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ProductConfig {
	private static final Log logger = LogFactory.getLog(ProductConfig.class);

	private static XMLConfiguration confs = null;

	protected static XMLConfiguration getUserConf(final String productFilePath) {
		try {
			XMLConfiguration iniconf = new XMLConfiguration(productFilePath);
			iniconf.setAutoSave(false);
			iniconf.setEncoding("utf-8");
			return iniconf;
		} catch (Exception e) {
			logger.fatal(e.getMessage() + productFilePath, e);
			throw new RuntimeException(e.getMessage() + productFilePath, e);
		}
	}

	public static void updateSignText(String filePath, String signText) {
		confs = getUserConf(filePath);
		confs.setProperty("sign_text", signText);
		try {
			confs.save();
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
	}
	
	public static String getValue(String filePath,String key){
		confs = getUserConf(filePath);
		return confs.getString(key);
	}

}
